﻿using HashFoo.Rest.Common;
using Ninject.Modules;

namespace HashFooRest.App.Web.Config
{
    public class ResourceSerializerNinjectModule : NinjectModule
    {
        /// <summary>
        /// Loads the module into the kernel.
        /// </summary>
        public override void Load()
        {
            // add json serializer
            const string jsonMimeType = "application/json";
            Bind<IResourceSerializer>()
                .ToConstant(
                    new FuncResourceSerializer
                    {
                        AcceptMimeTypes = new[] { jsonMimeType },
                        ContentMimeType = jsonMimeType,
                        Writer = obj => Newtonsoft.Json.JsonConvert.SerializeObject(obj),
                        Reader = (data, type) => Newtonsoft.Json.JsonConvert.DeserializeObject(data, type)
                    });
        }
    }
}